//
//  BKUserRegisterProtocalController.m
//  bestkeep
//
//  Created by windCould on 16/12/12.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKUserRegisterProtocalController.h"
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"
@interface BKUserRegisterProtocalController ()<UIWebViewDelegate,NJKWebViewProgressDelegate>

@property (nonatomic,strong)UIWebView *  webview;
@property (nonatomic,strong)NJKWebViewProgressView * progressView;
@property (nonatomic,strong)NJKWebViewProgress * progressProxy;

@end


@implementation BKUserRegisterProtocalController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _progressProxy = [[NJKWebViewProgress alloc] init];
    _progressProxy.webViewProxyDelegate = self;
    _progressProxy.progressDelegate = self;
    self.view.backgroundColor=[UIColor whiteColor];
    CGRect navBounds = self.navigationController.navigationBar.bounds;
    CGRect barFrame = CGRectMake(0,
                                 navBounds.size.height - 2,
                                 navBounds.size.width,
                                 2);
    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [_progressView setProgress:0 animated:YES];
    [self.navigationController.navigationBar addSubview:_progressView];
    
    NSURL * url = [NSURL URLWithString:@"http://cdn.bestkeep.cn/ui/pc/agreement/bestkeep-agreement.html"];
    _webview = [[UIWebView alloc]initWithFrame:self.view.bounds];
    [_webview loadRequest:[NSURLRequest requestWithURL:url]];
    _webview.delegate = _progressProxy;
    [self.view addSubview:_webview];
    
}

-(void)viewWillAppear:(BOOL)animated
{
   self.navigationItem.title = @"BESTKEEP服务协议";
}

-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    _progressView.hidden=YES;
}
#pragma mark - webview代理方法
- (void)webViewDidStartLoad:(UIWebView *)webView {
    
    NSLog(@"加载页面。。。。。。");
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    //self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    NSLog(@"页面加载完毕");
    
    NSString *jsToGetHTMLSource = @"document.getElementsByTagName('html')[0].innerHTML";
    
    [self.webview stringByEvaluatingJavaScriptFromString:jsToGetHTMLSource];
}

#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
    
//    if (!self.title) {
//        
//        self.navigationItem.title = [_webview stringByEvaluatingJavaScriptFromString:@"document.title"];
//    }
}

@end
